/**
 * 
 */
package com.gs.gms.model.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 * @author Sabuj Das | sabuj.das@gmail.com
 *
 */
@Entity
@Table(name="GMS_USER_CONNECTION", 
	uniqueConstraints={@UniqueConstraint(columnNames={"SOURCE_USER_ID", "CONNECTED_USER_ID"})})
public class UserConnection {
	
	@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="CONNECTION_ID", unique=true, nullable=false, updatable=false)
	private Long connectionId;
	
	@Column(name="CONNECTION_STATUS", nullable=false, length=45, columnDefinition=" default 'ACTIVE' ")
	private String connectionStatus;
	
	@ManyToOne
	@JoinColumn(name="SOURCE_USER_ID")
	private User sourceUser;
	
	@OneToOne
	@JoinColumn(name="CONNECTED_USER_ID")
	private User connectedUser;
	
	public UserConnection() {
		// TODO Auto-generated constructor stub
	}

	public Long getConnectionId() {
		return connectionId;
	}

	public void setConnectionId(Long connectionId) {
		this.connectionId = connectionId;
	}

	public String getConnectionStatus() {
		return connectionStatus;
	}

	public void setConnectionStatus(String connectionStatus) {
		this.connectionStatus = connectionStatus;
	}

	public User getSourceUser() {
		return sourceUser;
	}

	public void setSourceUser(User sourceUser) {
		this.sourceUser = sourceUser;
	}

	public User getConnectedUser() {
		return connectedUser;
	}

	public void setConnectedUser(User connectedUser) {
		this.connectedUser = connectedUser;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((connectedUser == null) ? 0 : connectedUser.hashCode());
		result = prime * result
				+ ((sourceUser == null) ? 0 : sourceUser.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof UserConnection)) {
			return false;
		}
		UserConnection other = (UserConnection) obj;
		if (connectedUser == null) {
			if (other.connectedUser != null) {
				return false;
			}
		} else if (!connectedUser.equals(other.connectedUser)) {
			return false;
		}
		if (sourceUser == null) {
			if (other.sourceUser != null) {
				return false;
			}
		} else if (!sourceUser.equals(other.sourceUser)) {
			return false;
		}
		return true;
	}
	
}
